package com.sbtr.exception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sbtr.common.Response;

import feign.FeignException;

/**
 * 异常处理拦截器
 *
 * @author qiujun
 * @date 2019-10-30
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(value = BizException.class)
    public Response<Void> exceptionHandler(HttpServletRequest request, Exception e) throws FeignException {
        //绑定异常是需要明确提示给用户的
        BizException exception = (BizException) e;
        String msg = exception.getMessage();
        int code = exception.getCode();
        return Response.error(code, msg);

    }
}

